﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using WPFTrees.DataStructures;
using WPFTrees.Parser;

namespace WPFTrees.Tests
{
    [TestFixture]
    [Platform("NET-4.0")]
    class TreeToolsTest
    {
        //
        // Otestuje
        //
        [Test]
        public void RotateLeftFourNodes()
        {
            NewickNode firstNode = new NewickNode("first",true);
            NewickNode secondNode = new NewickNode("second",true);
            NewickNode thirdNode = new NewickNode("third",true);
            NewickNode fourthNode = new NewickNode("fourth",true);

            NTreeNode<NewickNode> root = new NTreeNode<NewickNode>(new NewickNode("root",false),4);
            NTreeNode<NewickNode> first = new NTreeNode<NewickNode>(firstNode,0);
            NTreeNode<NewickNode> second = new NTreeNode<NewickNode>(secondNode, 0);
            NTreeNode<NewickNode> third = new NTreeNode<NewickNode>(thirdNode, 0);
            NTreeNode<NewickNode> fourth = new NTreeNode<NewickNode>(fourthNode, 0);

            root.AddNode(first);
            root.AddNode(second);
            root.AddNode(third);
            root.AddNode(fourth);

            WPFTrees.Tools.TreeTools.RotateLeft(root);

            NTreeNode<NewickNode>[] expected = new NTreeNode<NewickNode>[]{second,third,fourth,first};
            NUnit.Framework.CollectionAssert.AreEqual(expected, root.Children);

            WPFTrees.Tools.TreeTools.RotateLeft(root);

            expected = new NTreeNode<NewickNode>[] { third, fourth, first, second };
            NUnit.Framework.CollectionAssert.AreEqual(expected, root.Children);

            WPFTrees.Tools.TreeTools.RotateLeft(root);

            expected = new NTreeNode<NewickNode>[] { fourth, first, second, third };
            NUnit.Framework.CollectionAssert.AreEqual(expected, root.Children);

            WPFTrees.Tools.TreeTools.RotateLeft(root);

            expected = new NTreeNode<NewickNode>[] { first, second, third, fourth };
            NUnit.Framework.CollectionAssert.AreEqual(expected, root.Children);
        }

        [Test]
        public void RotateRightFourNodes()
        {
            NewickNode firstNode = new NewickNode("first", true);
            NewickNode secondNode = new NewickNode("second", true);
            NewickNode thirdNode = new NewickNode("third", true);
            NewickNode fourthNode = new NewickNode("fourth", true);

            NTreeNode<NewickNode> root = new NTreeNode<NewickNode>(new NewickNode("root", false), 4);
            NTreeNode<NewickNode> first = new NTreeNode<NewickNode>(firstNode, 0);
            NTreeNode<NewickNode> second = new NTreeNode<NewickNode>(secondNode, 0);
            NTreeNode<NewickNode> third = new NTreeNode<NewickNode>(thirdNode, 0);
            NTreeNode<NewickNode> fourth = new NTreeNode<NewickNode>(fourthNode, 0);

            root.AddNode(first);
            root.AddNode(second);
            root.AddNode(third);
            root.AddNode(fourth);

            WPFTrees.Tools.TreeTools.RotateRight(root);

            NTreeNode<NewickNode>[] expected = new NTreeNode<NewickNode>[] { fourth, first,second, third};
            NUnit.Framework.CollectionAssert.AreEqual(expected, root.Children);

            WPFTrees.Tools.TreeTools.RotateRight(root);

            expected = new NTreeNode<NewickNode>[] { third, fourth, first, second };
            NUnit.Framework.CollectionAssert.AreEqual(expected, root.Children);

            WPFTrees.Tools.TreeTools.RotateRight(root);

            expected = new NTreeNode<NewickNode>[] {  second, third, fourth, first};
            NUnit.Framework.CollectionAssert.AreEqual(expected, root.Children);

            WPFTrees.Tools.TreeTools.RotateRight(root);

            expected = new NTreeNode<NewickNode>[] { first, second, third, fourth };
            NUnit.Framework.CollectionAssert.AreEqual(expected, root.Children);
        }
    }
}
